﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Linq;
using LPPA.Facturacion.Services.Logger;

namespace LPPA.Facturacion.Services.Logger
{
    public static class LogManager
    {
		/// <summary>
		/// Escribir log para registrar ERROR.
		/// </summary>
		/// <param name="Message"></param>
		/// <param name="StackTrace"></param>
        public static void WriteError(string Message, string StackTrace)
        {
            try
            {
                using (DataAccess.dcEdenorteDataContext context = new DataAccess.dcEdenorteDataContext(CommonsValues.ConnectionString))
                {
                    var bitacoraItem = new DataAccess.Bitacora()
                    {
                        FechaHorario = DateTime.Now, 
                        Message = Message,
                        TipoLog = Convert.ToInt32(SupportLogger.TipoLog.Error),
                        StackTrace = StackTrace
                    };

                    context.Bitacoras.InsertOnSubmit(bitacoraItem);
                    context.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
		
		/// <summary>
		/// Escribir log para registrar Información.
		/// </summary>
		/// <param name="Message"></param>
		/// <param name="StackTrace"></param>
        public static void WriteInfo(string Message, string StackTrace)
        {
            try
            {
                using (DataAccess.dcEdenorteDataContext context = new DataAccess.dcEdenorteDataContext(CommonsValues.ConnectionString))
                {
                    var bitacoraItem = new DataAccess.Bitacora()
                    {
                        FechaHorario = DateTime.Now,
                        Message = Message,
                        TipoLog = Convert.ToInt32(SupportLogger.TipoLog.Information),
                        StackTrace = StackTrace
                    };

                    context.Bitacoras.InsertOnSubmit(bitacoraItem);
                    context.SubmitChanges();
                }
            }
            catch (Exception)
            {

                throw;
            }
        }

		/// <summary>
		/// Escribir log para registrar información en DEBUG.
		/// </summary>
		/// <param name="Message"></param>
		/// <param name="StackTrace"></param>
        public static void WriteDebug(string Message, string StackTrace)
        {
            try
            {
                using (DataAccess.dcEdenorteDataContext context = new DataAccess.dcEdenorteDataContext(CommonsValues.ConnectionString))
                {
                    var bitacoraItem = new DataAccess.Bitacora()
                    {
                        FechaHorario = DateTime.Now,
                        Message = Message,
                        TipoLog = Convert.ToInt32(SupportLogger.TipoLog.Debug)
                    };

                    context.Bitacoras.InsertOnSubmit(bitacoraItem);
                    context.SubmitChanges();
                }
            }
            catch (Exception)
            {

                throw;
            }
        }

		/// <summary>
		/// Escribir log para registrar un Warning.
		/// </summary>
		/// <param name="Message"></param>
        public static void WriteWarning(string Message)
        {
			try
            {
                using (DataAccess.dcEdenorteDataContext context = new DataAccess.dcEdenorteDataContext(CommonsValues.ConnectionString))
                {
                    var bitacoraItem = new DataAccess.Bitacora()
                    {
                        FechaHorario = DateTime.Now,
                        Message = Message,
                        TipoLog = Convert.ToInt32(SupportLogger.TipoLog.Warning)
                    };

                    context.Bitacoras.InsertOnSubmit(bitacoraItem);
                    context.SubmitChanges();
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
